<!DOCTYPE html>
<html>
<head>
    <title></title>
    <% include ../include/css_header.html %>
    <style>
        .haohouhu{
            height: 120px;
            position: absolute;
            right: 10px;
            top: 30px;
        }
    </style>
</head>
<body class="actlist_bg">
<div class="container">
    <div style="height: 20px"></div>
    <div class="row">
        <div class="col-xs-12">
            <div class="jumbotron" style="position: relative;background-color: #ffffff">
                <h1>壕赏钱<br/><%=order.totalFee %>大洋!</h1>
                <!--<p>"小礼物"请笑纳 →</p>-->
               <!-- <p><button type="button" class="btn btn-lg btn-primary" onclick="callAddr();">选择收货地址</button></p>-->
                <img src="/guiqiu.jpg" class="haohouhu">
                <div id="address">

                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <button type="button" class="btn btn-success btn-lg btn-block" onclick="callPay();">打赏!</button>
        </div>
    </div>
    <div style="height: 180px;"></div>
    <% include ../include/copyright.html %>
</div>
<% include ../include/js_footer.html %>
<script>
    var appid = '<%=params.appId %>';
    var timeStamp = '<%=params.timeStamp %>';
    var nonceStr = '<%=params.nonceStr %>';
    var package = '<%=params.package %>';
    var paySign = '<%=params.paySign %>';
    var code = '<%=authCode %>';
    var address = {};
    function callPay(){
        _createOrder(function(err, resp){
            WeixinJSBridge.invoke('getBrandWCPayRequest', {
                'appId': appid,
                'timeStamp': timeStamp,
                'nonceStr': nonceStr,
                'package': package,
                'signType': 'MD5',
                'paySign': paySign
            }, function(res){
                //alert(res.err_code+res.err_desc+res.err_msg);
                if(res.err_msg == 'get_brand_wcpay_request:ok'){
                    //TODO:跳转成功页面
                    AlertBox.showAlert('<%=resultMsg %>', true, function(){
                        AlertBox.closeAlertBox();
                        window.location.href = '/tuhaolist'
                    })
                }else{
                    alert('请再试一次吧...');
                }
            })
        })
    }
    function _createOrder(cb){
        /*if(!address.reciver){
            return alert('需要收件地址啊~');
        }*/
        $.post('/createOrder', {
            factionId: '5410286a7c99781e517c7d65',
            tradeNo: '<%=order.tradeNo %>',
            totalFee: '<%=order.totalFee %>',
            goodsId: '<%=order.id %>',
            goodsName: '<%=order.goodsName %>',
            address: address
        }, function(err, data){
            cb(err, data);
        })
    }
    function callAddr(){
        $.post('/getWechatAddress', {
            code: code
        }, function(res){
            if(res.error) return alert('....');
            var params = res.params;
            WeixinJSBridge.invoke('editAddress',{
                "appId": params.appId,
                "scope": "jsapi_address",
                "signType": "sha1",
                "addrSign": params.addrSign,
                "timeStamp": params.timeStamp,
                "nonceStr": params.nonceStr
            }, function(res){
                address = {
                    reciver: res.userName,
                    city: res.addressCitySecondStageName+res.addressCountiesThirdStageName,
                    detail: res.addressDetailInfo,
                    postal: res.addressPostalCode,
                    contact: res.telNumber
                }
                var html = '<ul>\
                                <li>收货人：'+res.userName+'</li>\
                                <li>城市：'+res.addressCitySecondStageName+res.addressCountiesThirdStageName+'</li>\
                                <li>详细地址：'+res.addressDetailInfo+'</li>\
                                <li>邮政编码：'+res.addressPostalCode+'</li>\
                                <li>联系方式：'+res.telNumber+'</li>\
                            </ul>';
                $('#address').html(html)
            })
        })
    }
</script>
</body>
</html>